import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { sysTenantGenerateCodeApi, sysTenantGetApi } from '/@/api/baas/sysTenant';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      fixed: 'left',
      width: 100,
      defaultHidden: true,
    },
    {
      title: 'LOGO',
      width: 120,
      dataIndex: ['sysTenantExtWeb', 'logo'],
      key: 'logo',
      align: 'center',
      // customRender: (record) => {
      //   if (record.value) {
      //     return <img width="100" src={record.value} />;
      //   } else {
      //     return <span>暂无图像</span>;
      //   }
      // },
      fixed: true,
    },
    {
      title: '租户编码',
      dataIndex: 'tenantCode',
      width: 220,
      helpMessage: '租户编码租户唯一识别信息',
      fixed: true,
    },
    {
      align: 'left',
      title: '租户名称',
      dataIndex: 'name',
      //fixed: true,
    },
    {
      title: '联系方式',
      width: 150,
      dataIndex: 'tel',
    },
    {
      title: '电话',
      width: 150,
      dataIndex: 'phone',
    },
    {
      title: '传真',
      width: 150,
      dataIndex: 'fax',
    },
    {
      title: '地址',
      dataIndex: 'address',
      width: 150,
    },
    {
      title: '到期时间',
      width: 150,
      dataIndex: 'timeExpiration',
    },
    {
      title: '创建人',
      width: 150,
      dataIndex: 'createdBy',
    },
    {
      title: '创建时间',
      width: 150,
      dataIndex: 'createdTime',
    },
    {
      title: '描述',
      width: 150,
      dataIndex: 'description',
    },
    {
      title: '租户域名',
      width: 150,
      dataIndex: ['sysTenantExtWeb', 'domainName'],
    },
    {
      title: '企业名称',
      width: 150,
      dataIndex: ['sysTenantExtBusiness', 'firmName'],
      helpMessage: '企业名称，合同标准名称',
    },
    {
      title: '社会信用代码',
      width: 150,
      dataIndex: ['sysTenantExtBusiness', 'creditCode'],
      helpMessage: '企业名称，合同标准名称',
    },
    {
      title: '行政区划',
      width: 150,
      dataIndex: ['sysTenantExtBusiness', 'administrativeDivision'],
      helpMessage: '行政区划',
    },
    {
      title: '商务区划',
      width: 150,
      dataIndex: ['sysTenantExtBusiness', 'businessArea'],
    },
    {
      title: '商务负责人',
      width: 150,
      dataIndex: ['sysTenantExtBusiness', 'businessHead'],
    },
    {
      title: '网站标题',
      width: 150,
      dataIndex: ['sysTenantExtWeb', 'title'],
    },
    {
      title: '标语',
      width: 150,
      dataIndex: ['sysTenantExtWeb', 'slogan'],
    },
  ];
}

// 表单查询配置
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      {
        field: `tenantCode`,
        label: `租户编码`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `name`,
        label: `租户名称`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}

// 增加表单，参数
const colProps = {
  span: 8,
};

const defaultValue = await sysTenantGenerateCodeApi();

export const schemas: FormSchema[] = [
  {
    field: 'tenantCode',
    component: 'Input',
    label: '租户编码',
    colProps,
    helpMessage: '租户编码是后台自动生成',
    required: true,
    defaultValue,
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'name',
    component: 'Input',
    label: '租户名称',
    colProps,
    required: true,
  },
  {
    field: 'tel',
    component: 'Input',
    label: '联系方式',
    colProps,
    required: true,
  },
  {
    field: 'phone',
    component: 'Input',
    label: '电话',
    colProps,
    required: true,
  },
  {
    field: 'fax',
    component: 'Input',
    label: '传真',
    colProps,
  },
  {
    field: 'address',
    component: 'InputTextArea',
    label: '地址',
    colProps,
    required: true,
  },
  {
    field: 'enable',
    component: 'Switch',
    label: '是否可用',
    defaultValue: true,
    colProps,
    helpMessage: '默认为可用',
    required: true,
  },
  {
    field: 'timeExpiration',
    component: 'DatePicker',
    label: '到期时间',
    colProps,
    required: true,
  },
  {
    field: 'description',
    component: 'InputTextArea',
    label: '描述',
    colProps,
    required: true,
  },
];

export async function getTenantById(id): any {
  const tenant = await sysTenantGetApi(id);
  return tenant;
}
